package com.yf.broadcastsender;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	public void sendBroadcast(View v) {
		Intent intent = new Intent();
		intent.setAction("com.yf.mybroadcast");
		intent.putExtra("subject", "hello");
		sendBroadcast(intent);
	}

	public void sendOrderedBroadcast(View v) {
		Intent intent = new Intent();
		intent.setAction("com.yf.sendrice");
		// 收到广播时需要的权限
		String receiverPermission = null;
		// 作为最终的广播接收者
		BroadcastReceiver resultReceiver = new FinalReceiver();
		// 处理最终的广播接收者用到的handler如果传null会在主线程处理
		Handler scheduler = null;
		int initialCode = 0;
		// 初始化的数据
		String initialData = "皇帝发放赈灾粮，每人100斤";
		Bundle initialExtras = null;
		sendOrderedBroadcast(intent, receiverPermission, resultReceiver, scheduler, initialCode, initialData,
				initialExtras);
	}
}
